package com.fenxiangle.yueding.common.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.fenxiangle.yueding.R;


public class ToastUtils {

    //在自己内部定义自己的一个实例，只供内部调用
    private static final ToastUtils instance = new ToastUtils();

    private ToastUtils() {
    }

    //这里提供了一个供外部访问本class的静态方法，可以直接访问
    public static ToastUtils getInstance() {
        return instance;
    }

    public void show(Context context, String msg) {
        try {
            //获取布局xml
            View tempView = LayoutInflater.from(context).inflate(R.layout.login_message, null);
            TextView textView =tempView.findViewById(R.id.error);
            //添加需要显示的信息
            textView.setText(msg);

            Toast toast = new Toast(context);
            //显示在屏幕的中间
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.setView(tempView);
            toast.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
